package com.myastro.opengles;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.myastro.HelperFunction;
import com.myastro.main.GLSurfaceManager;

public class GLRendererActivity extends Activity {


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        int whichLesson = getIntent().getIntExtra("lesson", 0);
        
        mGLView = new GLSurfaceManager(this, whichLesson);
        setContentView(mGLView);
    }

    @Override
    protected void onPause() {
    	mGLView.onPause();
    	super.onPause();
        
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }
    
    @Override
    protected void onDestroy() {
    	mGLView.doDestroy();
    	mGLView = null;
    	
    	super.onDestroy();
    }
    
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		
		menu.add(0, MENU1, Menu.NONE, "Filter");
		menu.add(0, MENU2, Menu.NONE, "Lighting");
		menu.add(0, MENU3, Menu.NONE, "Blending");
		
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		
		switch (item.getItemId()) 
		{
		case (MENU1):
			
			filter = (filter+1) % 3;
		
			if (filter == 0) {
				Toast.makeText(this, "GL_NEAREST", 1000).show();
			} else if (filter == 1) {
				Toast.makeText(this, "GL_LINEAR", 1000).show();
			} else if (filter == 2) {
				Toast.makeText(this, "GL_LINEAR_MIPMAP_NEAREST", 1000).show();
			}
		
			mGLView.handleKeyPress(HelperFunction.EVENT_KEY_CODE_F, true);
			
			break;
		
		case (MENU2):
			
			light = !light;
			
			if (light == true) {
				Toast.makeText(this, "Light On", 1000).show();
			} else {
				Toast.makeText(this, "Light Off", 1000).show();
			}
		
			mGLView.handleKeyPress(HelperFunction.EVENT_KEY_CODE_L, true);
			
			break;
		
		case (MENU3):
			
			blend = !blend;
		
			if (blend == true) {
				Toast.makeText(this, "Blend On", 1000).show();
			} else {
				Toast.makeText(this, "Blend Off", 1000).show();
			}
		
			mGLView.handleKeyPress(HelperFunction.EVENT_KEY_CODE_B, true);
			
			break;
		}
		
		return true;
	}
	
	private int 	filter = 0;
	private boolean light = true;
	private boolean blend = true;
	
	// ------------------ static --------------------
    
    static {
    	final String LIB_NAME = "native.renderer";
		//Log.i(TAG, "loading JNI lib using absolute path");
        System.loadLibrary(LIB_NAME);
    }
    
    
    // MENU
	static final private int MENU1 = Menu.FIRST;
	static final private int MENU2 = MENU1 + 1;
	static final private int MENU3 = MENU1 + 2;
	static final private int MENU4 = MENU1 + 3;
	static final private int MENU5 = MENU1 + 4;
	static final private int MENU6 = MENU1 + 5;
	static final private int MENU7 = MENU1 + 6;
    //
    
    // member variables
    private GLSurfaceManager mGLView;
    
    // Debug
    private static final String TAG = "GLRendererActivity";
    private boolean Debug = false;
	
}
